package com.jzo2o.foundations.controller.operation;


import com.jzo2o.common.model.PageResult;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.service.IServeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 服务表 前端控制器
 * </p>
 *
 * @author liuyp
 * @since 2024-12-11
 */
@RestController
@Api(tags = "运营端 - 区域服务相关接口")
@RequestMapping("/operation/serve")
public class ServeController {
    @Resource
    private IServeService serveService;

    @GetMapping("/page")
    @ApiOperation("区域服务分页查询")
    public PageResult<ServeResDTO> page(ServePageQueryReqDTO dto){
        return serveService.page(dto);
    }

    @PostMapping("/batch")
    @ApiOperation("区域服务批量添加")
    public void add(@RequestBody List<ServeUpsertReqDTO> list){
        serveService.add(list);
    }

    @PutMapping("/{serveId}")
    @ApiOperation("区域服务修改价格")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "serveId", value = "区域服务id", required = true, dataTypeClass = Long.class),
            @ApiImplicitParam(name = "price", value = "价格", required = true, dataTypeClass = BigDecimal.class)
    })
    public void updatePrice(@PathVariable("serveId") Long serveId,
                            @RequestParam("price") BigDecimal price){
        serveService.updatePrice(serveId, price);
    }

    @PutMapping("/onSale/{serveId}")
    @ApiOperation("区域服务上架")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "serveId", value = "区域服务id", required = true, dataTypeClass = Long.class)
    })
    public void onSale(@PathVariable("serveId") Long serveId){
        serveService.onSale(serveId);
    }
}
